package com.googlecode.economini.issues;

import java.util.concurrent.Executors;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

public class IssueService extends Service {

  private ListeningExecutorService executor;
  private IssueManager issueManager;
  private IssueStore issueStore;

  @Override
  public void onCreate() {
    super.onCreate();

    executor = MoreExecutors.listeningDecorator(Executors
        .newSingleThreadExecutor(new ThreadFactoryBuilder()
            .setNameFormat("issueservice-%s")
            .build()));
    issueStore = new IssueStore(this);
    issueManager = new IssueManager(executor, issueStore, getContentResolver());
  }

  @Override
  public void onDestroy() {
    executor.shutdownNow();
    issueStore.close();
    super.onDestroy();
  }

  @Override
  public IBinder onBind(Intent intent) {
    return issueManager;
  }
}
